#!/bin/sh

export MAKEFLAGS=""
top_srcdir="$(make -s echo-topdir 2>/dev/null)"

#
# Check for Doxygen warnings
#
nfiles="$(grep -c "Parsing file" < "${top_srcdir}/doc/doxygen.log")"
if nfails="$(grep -c Warning: "${top_srcdir}/doc/doxygen.log" 2>/dev/null)"; then
  grep Warning: "${top_srcdir}/doc/doxygen.log" | sed 's/\(.\{75\}\)...*/\1 .../'
fi

echo "$nfiles files, $nfails visible errors in documentation"

# Make errors non-fatal on Darwin, because Travis-CI always
# has outdated software.
if test "$(uname -s)" = "Darwin"; then
  exit 0
fi

if test "$nfails" != "0"; then
  exit 1
fi

exit 0

